package sythreeduixiang;
public class Student extends Person {
    private Course selectedCourse; // 所选课程
    // 子类构造方法：通过super()调用父类构造
    public Student(String studentId, String name, String gender) {
        super(studentId, name, gender); // 调用父类的构造方法
    }
    // 选课方法
    public void selectCourse(Course course) {
        this.selectedCourse = course;
        System.out.println(name + "同学选了《" + course.getCourseName() + "》课程");
    }
    // 退课方法
    public void dropCourse() {
        if (selectedCourse != null) {
            System.out.println(name + "同学退选了《" + selectedCourse.getCourseName() + "》课程");
            this.selectedCourse = null;
        } else {
            System.out.println(name + "同学未选任何课程，无法退课");
        }
    }
    // 重写父类的printSchedule方法：打印学生课表
    public void printSchedule() {
        if (selectedCourse != null) {
            System.out.println("==========" + name + "的课表==========");
            super.printInfo(); // 调用父类的printInfo方法
            System.out.println("课程名称：" + selectedCourse.getCourseName());
            System.out.println("上课地点：" + selectedCourse.getLocation());
            System.out.println("上课时间：" + selectedCourse.getTime());
            System.out.println("授课教师编号：" + selectedCourse.getTeacherId());
            System.out.println("=================================");
        } else {
            System.out.println(name + "同学未选任何课程，课表为空");
        }
    }
    // Getter方法
    public Course getSelectedCourse() {
        return selectedCourse;
    }
}